import { openPage } from '../../utils/map/open'
const app = getApp()
Page({
  data: {
    imgurl: app.globalData.imgurl,
    touchStartTime: 0, // 触摸开始时间
    touchEndTime: 0, // 触摸结束时间
    lastTapTime: 0, // 最后一次单击事件点击发生时间
  },
  onLoad({ type, s_id }) {
    wx.setNavigationBarTitle({
      title: type == 3 ? '团购介绍' : '玩习课介绍',
    })
    this.setData({ type, s_id })
    this._getDetail(s_id)
    this._getExplanation(s_id, type)
  },
  // 获取详情
  async _getDetail(s_id) {
    let { code, data } = await wx.requestAsync({
      url: '/shop/detail',
      data: {
        s_id,
      },
    })
    if (code == 0) {
      data.pic = this.data.imgurl + data.pic
      this.setData(data)
    }
  },
  // 打开导航
  openMap({ timeStamp }) {
    const {
      touchEndTime,
      touchStartTime,
      lastTapTime,
      p_name,
      c_name,
      a_name,
      address,
    } = this.data
    // 控制点击事件在350ms内触发，加这层判断是为了防止长按时会触发点击事件
    if (touchEndTime - touchStartTime < 350) {
      // 更新最后一次点击时间
      this.setData({
        lastTapTime: timeStamp,
      })
      // 如果两次点击时间在300毫秒内，则认为是双击事件
      if (timeStamp - lastTapTime > 300) {
        // do something 点击事件具体执行那个业务
        openPage({ p_name, c_name, a_name, address }, this)
      }
    }
  },
  // 获取游戏说明
  async _getExplanation(s_id, type) {
    let { code, data } = await wx.requestAsync({
      url: '/shop/content',
      data: {
        page: 1,
        s_id,
        type,
      },
    })
    if (code == 0) {
      this.setData({ content: data })
    }
  },
  // 预约
  _toBirthday() {
    const { s_id, type } = this.data
    if (type == 3) {
      wx.navigateTo({
        url: '/pages/birthday/birthday?s_id=' + s_id,
      })
    } else {
      wx.navigateTo({
        url: '/pages/play/play?s_id=' + s_id,
      })
    }
  },
})
